package com.test.javase;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/5/17
 * 2.控制台输入一组数据，请编写任意一种排序算法进行升序排列
 */
public class Sort {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("请输入要排序的整数个数: ");
        int n = scanner.nextInt();

        int[] arr = new int[n];

        System.out.println("请输入" + n + "个整数:");
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        System.out.println("升序排序后的结果:");
        System.out.println(Arrays.toString(arr));
        scanner.close();
    }
}
